home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2003 November / PCWK1103B.iso / DesignCAD 3D Max PLUS trial 30 / DATA1.CAB / Example_Files / Sample_Macros / LineByLine.d3m < prev    next >
Encoding:
Text File  |  2003-09-29  |  2.0 KB  |  104 lines

  1. ' This program draws one (or two) 2-point line segment with a specific distance and 3 (or 4) input points.
  2. '   Point 1 defines the starting endpoint of the line
  3. '   Point 2 and 3 define a line that contains the ending point of the 2-point line segment
  4. '      as well as the direction of the result line segment
  5. '   Point 4 is optional for drawing two lines with one on each side
  6. '
  7.  
  8. SETPOINT "Set points: 1) Starting point, 2,3) A line that contains the ending point, [ 4) Optional for both sides", 4
  9. NPTS = sys(1)
  10. IF NPTS < 3 THEN
  11.   END
  12. END IF
  13.  
  14. POINTVAL CX CY CZ 1
  15. POINTVAL EX1 EY1 EZ1 2
  16. POINTVAL EX2 EY2 EZ2 3
  17.  
  18. IF NPTS < 4 THEN
  19.   A$ = "S"
  20. ELSE
  21.   A$ = "D"
  22. END IF
  23.  
  24. DX = EX2 - EX1
  25. DY = EY2 - EY1
  26. DZ = EZ2 - EZ1
  27. D = DX * DX + DY * DY + DZ * DZ
  28.  
  29. IF D = 0 THEN
  30.   MESSAGE "ERROR: The 2nd and 3rd points are identical."
  31.   END
  32. END IF
  33.  
  34. INPUT "Enter the length of the line: ", R
  35.  
  36. IF R <= 0 THEN
  37.   MESSAGE "ERROR: The length of the line must be greater than zero."
  38.   END
  39. END IF
  40.  
  41. VX = EX2 - EX1
  42. VY = EY2 - EY1
  43. VZ = EZ2 - EZ1
  44.  
  45. R2 = R * R
  46.  
  47. A = VX * VX + VY * VY + VZ * VZ
  48. B = 2 * (VX * (EX1 - CX) + VY * (EY1 - CY) + VZ * (EZ1 - CZ))
  49. C = (EX1 - CX) * (EX1 - CX) + (EY1 - CY) * (EY1 - CY) + (EZ1 - CZ) * (EZ1 - CZ) - R2
  50.  
  51. D = B * B - 4 * A * C
  52.  
  53. IF D < 0 THEN
  54.   MESSAGE "ERROR: Cannot draw the line with the input points."
  55.   END
  56. END IF
  57.  
  58. D = SQRT(D)
  59. A = 2 * A
  60.  
  61. T1 = (D - B) / A
  62. T2 = -(B + D) / A
  63.  
  64. X1 = EX1 + T1 * VX
  65. Y1 = EY1 + T1 * VY
  66. Z1 = EZ1 + T1 * VZ
  67.  
  68. X2 = EX1 + T2 * VX
  69. Y2 = EY1 + T2 * VY
  70. Z2 = EZ1 + T2 * VZ
  71.  
  72. IF A$ = "D" THEN
  73.   >LINE
  74.   {
  75.     <POINTXYZ [CX, CY, CZ]
  76.     <POINTXYZ [X1, Y1, Z1]
  77.     }
  78.   >LINE
  79.   {
  80.     <POINTXYZ [CX, CY, CZ]
  81.     <POINTXYZ [X2, Y2, Z2]
  82.     }
  83. ELSE
  84.   DX = X2 - X1
  85.   DY = Y2 - Y1
  86.   DZ = Z2 - Z1
  87.   D = DX * VX + DY * VY + DZ * VZ
  88.  
  89.   IF D < 0 THEN
  90.     >LINE
  91.     {
  92.       <POINTXYZ [CX, CY, CZ]
  93.       <POINTXYZ [X1, Y1, Z1]
  94.       }
  95.   ELSE
  96.     >LINE
  97.     {
  98.       <POINTXYZ [CX, CY, CZ]
  99.       <POINTXYZ [X2, Y2, Z2]
  100.       }
  101.   END IF
  102. END IF
  103.  
  104.